<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中文名称-图谱" prop="chineseNameKg">
        <el-input
          v-model="queryParams.chineseNameKg"
          placeholder="请输入中文名称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称-图谱" prop="englishNameKg">
        <el-input
          v-model="queryParams.englishNameKg"
          placeholder="请输入英文名称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文简称" prop="englishAbbreviation">
        <el-input
          v-model="queryParams.englishAbbreviation"
          placeholder="请输入英文简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文简称-图谱" prop="englishAbbreviationKg">
        <el-input
          v-model="queryParams.englishAbbreviationKg"
          placeholder="请输入英文简称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家/地区" prop="countryRegion">
        <el-input
          v-model="queryParams.countryRegion"
          placeholder="请输入国家/地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型-图谱" prop="typeKg">
        <el-input
          v-model="queryParams.typeKg"
          placeholder="请输入类型-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:platform:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:platform:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:platform:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="platformList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="中文名称" show-overflow-tooltip align="center" prop="chineseName" />
      <el-table-column label="中文名称-图谱"  show-overflow-tooltip   align="center" prop="chineseNameKg" />
      <el-table-column label="英文名称"   show-overflow-tooltip  align="center" prop="englishName" />
      <el-table-column label="英文名称-图谱"  show-overflow-tooltip   align="center" prop="englishNameKg" />
      <el-table-column label="英文简称"   show-overflow-tooltip  align="center" prop="englishAbbreviation" />
      <el-table-column label="英文简称-图谱"  show-overflow-tooltip   align="center" prop="englishAbbreviationKg" />
      <el-table-column label="国家/地区"  show-overflow-tooltip   align="center" prop="countryRegion" />
      <el-table-column label="类型"  show-overflow-tooltip   align="center" prop="type" />
      <el-table-column label="类型-图谱"  show-overflow-tooltip   align="center" prop="typeKg" />
      <el-table-column label="定义"   show-overflow-tooltip  align="center" prop="definition" />
      <el-table-column label="状态"   show-overflow-tooltip  align="center" prop="status" />
      <el-table-column label="项目背景"  show-overflow-tooltip   align="center" prop="projectBackground" />
      <el-table-column label="愿景目标"  show-overflow-tooltip   align="center" prop="visionGoal" />
      <el-table-column label="功能架构"  show-overflow-tooltip   align="center" prop="functionalArchitecture" />
      <el-table-column label="运行环境"   show-overflow-tooltip  align="center" prop="operatingEnvironment" />
      <el-table-column label="特点创新"  show-overflow-tooltip   align="center" prop="featuresInnovation" />
      <el-table-column label="项目进展"  show-overflow-tooltip   align="center" prop="projectProgress" />
      <el-table-column label="开始时间"   show-overflow-tooltip  align="center" prop="startDate" />
      <el-table-column label="开始时间-图谱"  show-overflow-tooltip   align="center" prop="startDateKg" />
      <el-table-column label="经费预算"   show-overflow-tooltip   align="center" prop="budget" />
      <el-table-column label="演习验证"   show-overflow-tooltip  align="center" prop="exerciseVerification" />
      <el-table-column label="演习验证-图谱"   show-overflow-tooltip  align="center" prop="exerciseVerificationKg" />
      <el-table-column label="所属架构"   show-overflow-tooltip  align="center" prop="affiliatedArchitecture" />
      <el-table-column label="所属架构-图谱"   show-overflow-tooltip  align="center" prop="affiliatedArchitectureKg" />
      <el-table-column label="承建单位"  show-overflow-tooltip   align="center" prop="contractor" />
      <el-table-column label="承建单位-图谱"   show-overflow-tooltip  align="center" prop="contractorKg" />
      <el-table-column label="承包商"  show-overflow-tooltip   align="center" prop="subcontractor" />
      <el-table-column label="承包商-图谱"   show-overflow-tooltip  align="center" prop="subcontractorKg" />
      <el-table-column label="使用单位"  show-overflow-tooltip   align="center" prop="userUnit" />
      <el-table-column label="使用单位-图谱"  show-overflow-tooltip   align="center" prop="userUnitKg" />
      <el-table-column label="关键技术"  show-overflow-tooltip   align="center" prop="keyTechnology" />
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:platform:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:platform:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改武器平台对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="中文名称-图谱" prop="chineseNameKg">
          <el-input v-model="form.chineseNameKg" placeholder="请输入中文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="英文名称-图谱" prop="englishNameKg">
          <el-input v-model="form.englishNameKg" placeholder="请输入英文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文简称" prop="englishAbbreviation">
          <el-input v-model="form.englishAbbreviation" placeholder="请输入英文简称" />
        </el-form-item>
        <el-form-item label="英文简称-图谱" prop="englishAbbreviationKg">
          <el-input v-model="form.englishAbbreviationKg" placeholder="请输入英文简称-图谱" />
        </el-form-item>
        <el-form-item label="国家/地区" prop="countryRegion">
          <el-input v-model="form.countryRegion" placeholder="请输入国家/地区" />
        </el-form-item>
        <el-form-item label="类型-图谱" prop="typeKg">
          <el-input v-model="form.typeKg" placeholder="请输入类型-图谱" />
        </el-form-item>
        <el-form-item label="定义" prop="definition">
          <el-input v-model="form.definition" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="项目背景" prop="projectBackground">
          <el-input v-model="form.projectBackground" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="愿景目标" prop="visionGoal">
          <el-input v-model="form.visionGoal" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="功能架构" prop="functionalArchitecture">
          <el-input v-model="form.functionalArchitecture" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="运行环境" prop="operatingEnvironment">
          <el-input v-model="form.operatingEnvironment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="特点创新" prop="featuresInnovation">
          <el-input v-model="form.featuresInnovation" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="项目进展" prop="projectProgress">
          <el-input v-model="form.projectProgress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startDate">
          <el-input v-model="form.startDate" placeholder="请输入开始时间" />
        </el-form-item>
        <el-form-item label="开始时间-图谱" prop="startDateKg">
          <el-input v-model="form.startDateKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经费预算" prop="budget">
          <el-input v-model="form.budget" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="演习验证" prop="exerciseVerification">
          <el-input v-model="form.exerciseVerification" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="演习验证-图谱" prop="exerciseVerificationKg">
          <el-input v-model="form.exerciseVerificationKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属架构" prop="affiliatedArchitecture">
          <el-input v-model="form.affiliatedArchitecture" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属架构-图谱" prop="affiliatedArchitectureKg">
          <el-input v-model="form.affiliatedArchitectureKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承建单位" prop="contractor">
          <el-input v-model="form.contractor" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承建单位-图谱" prop="contractorKg">
          <el-input v-model="form.contractorKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承包商" prop="subcontractor">
          <el-input v-model="form.subcontractor" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="承包商-图谱" prop="subcontractorKg">
          <el-input v-model="form.subcontractorKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="使用单位" prop="userUnit">
          <el-input v-model="form.userUnit" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="使用单位-图谱" prop="userUnitKg">
          <el-input v-model="form.userUnitKg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="关键技术" prop="keyTechnology">
          <el-input v-model="form.keyTechnology" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="3"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="3"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="3"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="3"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPlatform, getPlatform, delPlatform, addPlatform, updatePlatform } from "@/api/business/platform";
import { guid } from '@/utils/utils'
import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
export default {
  components: { Pictures,FileUpload },
  name: "Platform",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 武器平台表格数据
      platformList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        englishAbbreviation: null,
        englishAbbreviationKg: null,
        countryRegion: null,
        type: null,
        typeKg: null,
        definition: null,
        status: null,
        projectBackground: null,
        visionGoal: null,
        functionalArchitecture: null,
        operatingEnvironment: null,
        featuresInnovation: null,
        projectProgress: null,
        startDate: null,
        startDateKg: null,
        budget: null,
        exerciseVerification: null,
        exerciseVerificationKg: null,
        affiliatedArchitecture: null,
        affiliatedArchitectureKg: null,
        contractor: null,
        contractorKg: null,
        subcontractor: null,
        subcontractorKg: null,
        userUnit: null,
        userUnitKg: null,
        keyTechnology: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询武器平台列表 */
    getList() {
      this.loading = true;
      listPlatform(this.queryParams).then(response => {
        this.platformList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseName: null,
        chineseNameKg: null,
        englishName: null,
        englishNameKg: null,
        englishAbbreviation: null,
        englishAbbreviationKg: null,
        countryRegion: null,
        type: null,
        typeKg: null,
        definition: null,
        status: null,
        projectBackground: null,
        visionGoal: null,
        functionalArchitecture: null,
        operatingEnvironment: null,
        featuresInnovation: null,
        projectProgress: null,
        startDate: null,
        startDateKg: null,
        budget: null,
        exerciseVerification: null,
        exerciseVerificationKg: null,
        affiliatedArchitecture: null,
        affiliatedArchitectureKg: null,
        contractor: null,
        contractorKg: null,
        subcontractor: null,
        subcontractorKg: null,
        userUnit: null,
        userUnitKg: null,
        keyTechnology: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加武器平台";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlatform(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改武器平台";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlatform(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlatform(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除武器平台编号为"' + ids + '"的数据项？').then(function() {
        return delPlatform(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/platform/export', {
        ...this.queryParams
      }, `platform_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
